﻿using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;

namespace Algoritmia.Problems.FractionalKnapsack
{
    public class GreedySuboptimalFractionalKnapsackSolver : IFractionalKnapsackSolver
    {
        #region Implementation of IFractionalKnapsackSolver

        public IEnumerable<double> Solve(double W, IEnumerable<double> w, IEnumerable<double> v)
        {
            var weightsList = w.ToList();
            var result = new double[weightsList.Count];
            for(int i = 0; i < weightsList.Count; i++)
            {
                result[i] = Math.Min(1.0, W/weightsList[i]);
                W -= result[i]*weightsList[i];
            }
            return result;
        }

        #endregion
    }
}
